﻿using System;
using System.Collections.ObjectModel;

using SBPweb.RIA.Client.Common.Collections;

using SBPweb.PROvibe.Shared.Library.Base;
using SBPweb.PROvibe.Shared.Library.Components;

namespace SBPweb.PROvibe.Client.Core.Services.ConfigurationProvider
{

    partial class Suite : ISuite
    {

        #region Fields

        private ManagableReadOnlyObservableList<IModule> observableModules;

        #endregion

        #region Properties

        internal ObservableCollection<IModule> modules
        {
            get
            {
                MaintainModulesCollections();
                return observableModules.ManagableItems;
            }
        }
        
        public ReadOnlyCollection<IModule> Modules
        {
            get
            {
                MaintainModulesCollections();
                return observableModules;
            }
        }

        public Version Version
        {
            get
            {
                if (string.IsNullOrEmpty(VersionAsString))
                {
                    return null;
                }
                return System.Version.Parse(VersionAsString);
            }
        }

        #endregion

        #region Methods

        private void MaintainModulesCollections()
        {
            lock (this)
            {
                if (observableModules == null)
                {
                    observableModules = new ManagableReadOnlyObservableList<IModule>();
                }
            }
        }

        public int CompareTo(object obj)
        {
            return CompareTo(obj as INameable);
        }

        public int CompareTo(IIndexable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Id.CompareTo(other.Id);
        }

        public int CompareTo(INameable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Name.CompareTo(other.Name);
        }

        public int CompareTo(IVersionable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Version.CompareTo(other.Version);
        }

        #endregion

    }

}